//
//  PurchaseListTableViewHeaderFooterView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/1.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "PurchaseListTableViewHeaderFooterView.h"

@implementation PurchaseListTableViewHeaderFooterView
{
    NSMutableArray *btnArr;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        CGFloat butWidth = kWidthProportion_In_iPhoneTriploid(75);
        btnArr = [NSMutableArray array];
        for (int i = 0; i < 3; i++) {
            GLGWButton *bottomBut = [[GLGWButton alloc] initWithTitle:@"刷新求购单" titleLableFont:SYSTEMFONT(12) titleLableColor:kColor_Rule_Yellow theCornerRadius:kHeightProportion_In_iPhoneTriploid(15) theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self.contentView];
            [bottomBut mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.contentView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15)-butWidth*i - kWidthProportion_In_iPhoneTriploid(10)*i);
                make.top.equalTo(self.contentView.mas_top).offset(0);
                make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(75)));
                make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
            }];
            [btnArr addObject:bottomBut];
            [bottomBut addTarget:self action:@selector(bottomAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return self;
}

- (void)bottomAction:(GLGWButton *)sender
{
    if (self.BlockBottomBtn) {
        self.BlockBottomBtn(sender, self.section);
    }
}

/*
 0: 刷新求购单
 1: 删除
 2: 查看退款
 3: 查看订单
 */

- (void)setDataInfoModel:(PurchaseAllListDataInfosModel *)dataInfoModel
{
    _dataInfoModel = dataInfoModel;
    
    // 0:全部 1：接受报价 2：已完成 3：已失效,
    NSInteger cout = 320;
    for (int i = 0; i < btnArr.count; i ++) {
        GLGWButton *btn = btnArr[i];
        btn.tag = cout;        
        switch (self.type) {
            case 0:
                if (dataInfoModel.status == 1) { // 求购状态 1接受报价中(当前时间<报价时限) 2已完成  3未成交(有过报价) 4已失效(到截止时间没有过报价)',
                    [self dataInfoGetOffer:i btn:btn num:cout];
                } else if (dataInfoModel.status == 2) {
                    [self dataInfoHaveDone:i btn:btn num:cout];
                } else if (dataInfoModel.status == 4) {
                    [self dataInfoHaveHasFailure:i btn:btn num:cout];
                }
                break;
            case 1:
                [self dataInfoGetOffer:i btn:btn num:cout];
                break;
            case 2:
                [self dataInfoHaveDone:i btn:btn num:cout];
                break;
            case 3:
                [self dataInfoHaveHasFailure:i btn:btn num:cout];
                break;
            default:
                break;
        }
    }
}

// 接受报价中
- (void)dataInfoGetOffer:(int)cou btn:(GLGWButton *)btn num:(NSInteger)num
{
    if (cou == 2 || cou == 1) {
        btn.hidden = YES;
    } else if (cou == 0) {
        [self btnStatus:btn titleStr:@"刷新求购单" textColor:@"#A89A60" layerColor:@"#A89A60" tag:num + 0];
    }
}

// 已完成
- (void)dataInfoHaveDone:(int)cou btn:(GLGWButton *)btn num:(NSInteger)num
{
    if (_dataInfoModel.type == 2) { // 定金求购
        if (cou == 2) {
            [self btnStatus:btn titleStr:@"删除" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 1];
        } else if (cou == 1) {
            [self btnStatus:btn titleStr:@"查看退款" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 2];
        } else if (cou == 0) {
            [self btnStatus:btn titleStr:@"查看订单" textColor:@"#A89A60" layerColor:@"#A89A60" tag:num + 3];
        }
    } else {
        if (cou == 2) {
            btn.hidden = YES;
        } else if (cou == 1) {
            [self btnStatus:btn titleStr:@"删除" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 1];
        } else if (cou == 0) {
            [self btnStatus:btn titleStr:@"查看订单" textColor:@"#A89A60" layerColor:@"#A89A60" tag:num + 3];
        }
    }
}

// 已失效
- (void)dataInfoHaveHasFailure:(int)cou btn:(GLGWButton *)btn num:(NSInteger)num
{
    if (_dataInfoModel.type == 2) { // 定金求购
        if (cou == 2) {
            btn.hidden = YES;
        } else if (cou == 1) {
            [self btnStatus:btn titleStr:@"删除" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 1];
        } else if (cou == 0) {
            [self btnStatus:btn titleStr:@"查看退款" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 2];
        }
    } else {
        if (cou == 2 || cou == 1) {
            btn.hidden = YES;
        } else if (cou == 0) {
            [self btnStatus:btn titleStr:@"删除" textColor:@"#666666" layerColor:@"#CCCCCC" tag:num + 1];
        }
    }
}

- (void)btnStatus:(GLGWButton *)btn titleStr:(NSString *)titleStr textColor:(NSString *)colorStr layerColor:(NSString *)layerColorStr tag:(NSInteger)tag
{
    [btn setTitle:titleStr forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateNormal];
    btn.layer.borderColor = [UIColor colorWithHexString:layerColorStr].CGColor;
    btn.tag = tag;
    btn.hidden = NO;
}

@end
